package com.lixh.sdk.base.util

import android.content.Context
import android.net.ConnectivityManager
import android.os.Handler
import android.os.Looper

val globalHandle = Handler(Looper.getMainLooper())
infix fun Boolean.isFalse(block: () -> Unit) {
    if (this) {
        block()
    }
}


//检查网络是否可用
fun isNetworkAvailable(): Boolean {
    val localNetworkInfo =
        (application.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager).activeNetworkInfo
    return localNetworkInfo != null && localNetworkInfo.isAvailable
}

//检测wifi是否连接
fun isWifiConnected(): Boolean {
    val localNetworkInfo =
        (application.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager).activeNetworkInfo
    return localNetworkInfo != null && localNetworkInfo.type == ConnectivityManager.TYPE_WIFI
}

/**
 * 检测3G是否连接
 */
fun is3gConnected(): Boolean {
    val localNetworkInfo =
        (application.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager).activeNetworkInfo
    return localNetworkInfo != null && localNetworkInfo.type == ConnectivityManager.TYPE_WIFI
}